import type { RouteRecordRaw } from 'vue-router'
import ToolBox from './ToolBox.vue'

// 默认图片（Base64格式）
const DEFAULT_IMAGES = {
  currency: '',
  date: '',
  base: '',
  case: '',
  css: '',
  regex: '',
  clock: '',
  countdown: '',
  pixel: '',
  base64: '',
  metadata: '',
  joiner: ''
}

// 工具分类
export const categories = {
  calculation: {
    name: '计算工具',
    icon: 'calculator',
    tools: [
      {
        path: 'calculator',
        name: '科学计算器',
        component: () => import('@/views/Toolbox/components/CalculatorTool.vue'),
        meta: {
          icon: 'calculator',
          description: '功能强大的科学计算器',
          image: DEFAULT_IMAGES.currency,
          defaultIcon: 'CalculatorOutlined'
        }
      },
      {
        path: 'currency-converter',
        name: '货币换算器',
        component: () => import('@/views/Toolbox/components/CurrencyConverter.vue'),
        meta: {
          icon: 'dollar',
          description: '支持全球主要货币的实时汇率换算',
          image: DEFAULT_IMAGES.currency,
          defaultIcon: 'DollarOutlined'
        }
      },
      {
        path: 'date-calculator',
        name: '日期计算器',
        component: () => import('@/views/Toolbox/components/DateCalculator.vue'),
        meta: {
          icon: 'calendar',
          description: '计算日期间隔、工作日等',
          image: DEFAULT_IMAGES.date,
          defaultIcon: 'CalendarOutlined'
        }
      }
    ]
  },
  conversion: {
    name: '转换工具',
    icon: 'swap',
    tools: [
      {
        path: 'base-converter',
        name: '进制转换器',
        component: () => import('@/views/Toolbox/components/BaseConverter.vue'),
        meta: {
          icon: 'number',
          description: '在二进制、八进制、十进制、十六进制之间转换',
          image: DEFAULT_IMAGES.base,
          defaultIcon: 'NumberOutlined'
        }
      },
      {
        path: 'case-converter',
        name: '大小写转换',
        component: () => import('@/views/Toolbox/components/CaseConverter.vue'),
        meta: {
          icon: 'font-size',
          description: '在大写、小写、驼峰等格式之间转换',
          image: DEFAULT_IMAGES.case,
          defaultIcon: 'FontSizeOutlined'
        }
      },
      {
        path: 'base64-converter',
        name: 'Base64转换',
        component: () => import('@/views/Toolbox/components/Base64Converter.vue'),
        meta: {
          icon: 'code',
          description: '文本与Base64编码互转',
          image: DEFAULT_IMAGES.base64,
          defaultIcon: 'CodeOutlined'
        }
      },
      {
        path: 'timestamp-converter',
        name: '时间戳转换',
        component: () => import('@/views/Toolbox/components/TimestampConverter.vue'),
        meta: {
          icon: 'clock',
          description: '时间戳与日期时间互转',
          image: DEFAULT_IMAGES.clock,
          defaultIcon: 'ClockCircleOutlined'
        }
      },
      {
        path: 'pinyin-converter',
        name: '拼音转换',
        component: () => import('@/views/Toolbox/components/PinyinConverter.vue'),
        meta: {
          icon: 'font-colors',
          description: '中文汉字转拼音',
          image: DEFAULT_IMAGES.case,
          defaultIcon: 'FontColorsOutlined'
        }
      }
    ]
  },
  development: {
    name: '开发工具',
    icon: 'code',
    tools: [
      {
        path: 'css-beautifier',
        name: 'CSS美化工具',
        component: () => import('@/views/Toolbox/components/CssBeautifier.vue'),
        meta: {
          icon: 'css3',
          description: '格式化和压缩CSS代码',
          image: DEFAULT_IMAGES.css,
          defaultIcon: 'Html5Outlined'
        }
      },
      {
        path: 'regex-tester',
        name: '正则测试器',
        component: () => import('@/views/Toolbox/components/RegexTester.vue'),
        meta: {
          icon: 'search',
          description: '正则表达式测试与验证',
          image: DEFAULT_IMAGES.regex,
          defaultIcon: 'SearchOutlined'
        }
      },
      {
        path: 'json-formatter',
        name: 'JSON格式化',
        component: () => import('@/views/Toolbox/components/JsonFormatter.vue'),
        meta: {
          icon: 'code',
          description: 'JSON数据格式化与压缩',
          image: DEFAULT_IMAGES.css,
          defaultIcon: 'CodeOutlined'
        }
      },
      {
        path: 'xml-beautifier',
        name: 'XML格式化',
        component: () => import('@/views/Toolbox/components/XmlBeautifier.vue'),
        meta: {
          icon: 'file-text',
          description: 'XML数据格式化与压缩',
          image: DEFAULT_IMAGES.css,
          defaultIcon: 'FileTextOutlined'
        }
      },
      {
        path: 'url-encoder',
        name: 'URL编解码',
        component: () => import('@/views/Toolbox/components/UrlEncoder.vue'),
        meta: {
          icon: 'link',
          description: 'URL编码与解码转换',
          image: DEFAULT_IMAGES.base64,
          defaultIcon: 'LinkOutlined'
        }
      },
      {
        path: 'http-status',
        name: 'HTTP状态码',
        component: () => import('@/views/Toolbox/components/HttpStatus.vue'),
        meta: {
          icon: 'api',
          description: 'HTTP状态码查询与说明',
          image: DEFAULT_IMAGES.metadata,
          defaultIcon: 'ApiOutlined'
        }
      },
      {
        path: 'ip-query',
        name: 'IP地址查询',
        component: () => import('@/views/Toolbox/components/IPQuery.vue'),
        meta: {
          icon: 'global',
          description: 'IP地址信息查询',
          image: DEFAULT_IMAGES.metadata,
          defaultIcon: 'GlobalOutlined'
        }
      }
    ]
  },
  text: {
    name: '文本工具',
    icon: 'file-text',
    tools: [
      {
        path: 'text-trimmer',
        name: '文本去重工具',
        component: () => import('@/views/Toolbox/components/TextTrimmer.vue'),
        meta: {
          icon: 'scissor',
          description: '去除文本中的重复内容',
          image: DEFAULT_IMAGES.case,
          defaultIcon: 'ScissorOutlined'
        }
      },
      {
        path: 'text-reverser',
        name: '文本反转工具',
        component: () => import('@/views/Toolbox/components/TextReverser.vue'),
        meta: {
          icon: 'swap',
          description: '反转文本内容',
          image: DEFAULT_IMAGES.case,
          defaultIcon: 'SwapOutlined'
        }
      },
      {
        path: 'text-sorter',
        name: '文本排序工具',
        component: () => import('@/views/Toolbox/components/TextSorter.vue'),
        meta: {
          icon: 'sort-ascending',
          description: '对文本行进行排序',
          image: DEFAULT_IMAGES.case,
          defaultIcon: 'SortAscendingOutlined'
        }
      },
      {
        path: 'line-numberer',
        name: '行号添加工具',
        component: () => import('@/views/Toolbox/components/LineNumberer.vue'),
        meta: {
          icon: 'ordered-list',
          description: '为文本添加行号',
          image: DEFAULT_IMAGES.case,
          defaultIcon: 'OrderedListOutlined'
        }
      },
      {
        path: 'text-diff',
        name: '文本对比工具',
        component: () => import('@/views/Toolbox/components/TextDiff.vue'),
        meta: {
          icon: 'diff',
          description: '对比两段文本的差异',
          image: DEFAULT_IMAGES.case,
          defaultIcon: 'DiffOutlined'
        }
      },
      {
        path: 'text-stats',
        name: '文本统计工具',
        component: () => import('@/views/Toolbox/components/TextStats.vue'),
        meta: {
          icon: 'bar-chart',
          description: '统计文本字数等信息',
          image: DEFAULT_IMAGES.case,
          defaultIcon: 'BarChartOutlined'
        }
      }
    ]
  },
  security: {
    name: '安全工具',
    icon: 'safety',
    tools: [
      {
        path: 'text-encryptor',
        name: '文本加密工具',
        component: () => import('@/views/Toolbox/components/TextEncryptor.vue'),
        meta: {
          icon: 'lock',
          description: '文本加密与解密',
          image: DEFAULT_IMAGES.base64,
          defaultIcon: 'LockOutlined'
        }
      },
      {
        path: 'md5-encoder',
        name: 'MD5编码工具',
        component: () => import('@/views/Toolbox/components/Md5Encoder.vue'),
        meta: {
          icon: 'safety',
          description: '计算文本的MD5值',
          image: DEFAULT_IMAGES.base64,
          defaultIcon: 'SafetyOutlined'
        }
      }
    ]
  },
  time: {
    name: '时间工具',
    icon: 'clock-circle',
    tools: [
      {
        path: 'world-clock',
        name: '世界时钟',
        component: () => import('@/views/Toolbox/components/WorldClock.vue'),
        meta: {
          icon: 'global',
          description: '查看全球各地时区的当前时间',
          image: DEFAULT_IMAGES.clock,
          defaultIcon: 'GlobalOutlined'
        }
      },
      {
        path: 'countdown',
        name: '倒计时器',
        component: () => import('@/views/Toolbox/components/Countdown.vue'),
        meta: {
          icon: 'hourglass',
          description: '创建自定义倒计时',
          image: DEFAULT_IMAGES.countdown,
          defaultIcon: 'HourglassOutlined'
        }
      }
    ]
  },
  image: {
    name: '图片工具',
    icon: 'picture',
    tools: [
      {
        path: 'image-pixelator',
        name: '图片像素化',
        component: () => import('@/views/Toolbox/components/ImagePixelator.vue'),
        meta: {
          icon: 'block',
          description: '将图片转换为像素风格',
          image: DEFAULT_IMAGES.pixel,
          defaultIcon: 'BlockOutlined'
        }
      },
      {
        path: 'image-to-base64',
        name: '图片转Base64',
        component: () => import('@/views/Toolbox/components/ImageToBase64.vue'),
        meta: {
          icon: 'file-image',
          description: '将图片转换为Base64编码',
          image: DEFAULT_IMAGES.base64,
          defaultIcon: 'FileImageOutlined'
        }
      },
      {
        path: 'image-metadata',
        name: '图片元数据',
        component: () => import('@/views/Toolbox/components/ImageMetadata.vue'),
        meta: {
          icon: 'info-circle',
          description: '查看图片的EXIF等元数据信息',
          image: DEFAULT_IMAGES.metadata,
          defaultIcon: 'InfoCircleOutlined'
        }
      },
      {
        path: 'image-joiner',
        name: '图片拼接',
        component: () => import('@/views/Toolbox/components/ImageJoiner.vue'),
        meta: {
          icon: 'layout',
          description: '将多张图片拼接成一张',
          image: DEFAULT_IMAGES.joiner,
          defaultIcon: 'LayoutOutlined'
        }
      },
      {
        path: 'image-compressor',
        name: '图片压缩',
        component: () => import('@/views/Toolbox/components/ImageCompressor.vue'),
        meta: {
          icon: 'compress',
          description: '压缩图片文件大小',
          image: DEFAULT_IMAGES.pixel,
          defaultIcon: 'CompressOutlined'
        }
      },
      {
        path: 'image-processor',
        name: '图片处理',
        component: () => import('@/views/Toolbox/components/ImageProcessor.vue'),
        meta: {
          icon: 'edit',
          description: '图片裁剪、旋转等基础处理',
          image: DEFAULT_IMAGES.pixel,
          defaultIcon: 'EditOutlined'
        }
      }
    ]
  },
  color: {
    name: '颜色工具',
    icon: 'bg-colors',
    tools: [
      {
        path: 'color-tools',
        name: '颜色工具集',
        component: () => import('@/views/Toolbox/components/ColorTools.vue'),
        meta: {
          icon: 'bg-colors',
          description: '颜色选择、转换、调色板等',
          image: DEFAULT_IMAGES.css,
          defaultIcon: 'BgColorsOutlined'
        }
      }
    ]
  },
  other: {
    name: '其他工具',
    icon: 'appstore',
    tools: [
      {
        path: 'qrcode-generator',
        name: '二维码生成',
        component: () => import('@/views/Toolbox/components/QRCodeGenerator.vue'),
        meta: {
          icon: 'qrcode',
          description: '生成自定义二维码',
          image: DEFAULT_IMAGES.metadata,
          defaultIcon: 'QrcodeOutlined'
        }
      },
      {
        path: 'markdown-preview',
        name: 'Markdown预览',
        component: () => import('@/views/Toolbox/components/MarkdownPreview.vue'),
        meta: {
          icon: 'file-markdown',
          description: 'Markdown实时预览',
          image: DEFAULT_IMAGES.css,
          defaultIcon: 'FileMarkdownOutlined'
        }
      }
    ]
  }
} as const

// 生成路由配置
export const toolboxRoutes: RouteRecordRaw[] = [
  {
    path: '/toolbox',
    name: '工具箱',
    component: ToolBox,
    children: [
      {
        path: '',
        name: 'toolbox-home',
        component: () => import('./ToolboxHome.vue')
      },
      ...Object.values(categories).reduce((acc, category) => {
        return [...acc, ...category.tools]
      }, [] as RouteRecordRaw[])
    ]
  }
]
